package com.fdb.efp.cus.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.cus.service.dao.CusHandoverLstDao;
import com.fdb.efp.cus.service.domain.CusHandoverLst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fdb.efp.cus.service.facade.CusHandoverLstService;
import com.fdb.efp.cus.service.vo.CusHandoverLstVO;
import com.fdb.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 客户移交明细				<p>
 * @author chenqm1
 * @date 2018-05-14
 */
@Service("cusHandoverLstService")
public class CusHandoverLstServiceImpl implements CusHandoverLstService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(CusHandoverLstServiceImpl.class);

	@Autowired
	private CusHandoverLstDao cusHandoverLstDao;
	
	/**
	 * 新增操作
	 */
	public int insertCusHandoverLst(List<CusHandoverLstVO> inCusHandoverLstVo) {
		logger.debug("当前新增数据为:"+ inCusHandoverLstVo.toString());
		int num = 0;
		try {
			@SuppressWarnings("unchecked")
			List<CusHandoverLst> cusHandoverLst = (List<CusHandoverLst>) beansCopy(inCusHandoverLstVo, CusHandoverLstVO.class);
			
			//beanCopy(inCusHandoverLstVo, cusHandoverLst);
			num = cusHandoverLstDao.insertCusHandoverLst(cusHandoverLst);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(CusHandoverLstVO inCusHandoverLstVo) {
		logger.debug("当前删除数据条件为:"+ inCusHandoverLstVo);
		int num = 0;
		try {
			CusHandoverLst cusHandoverLst = new CusHandoverLst();
			beanCopy(inCusHandoverLstVo, cusHandoverLst);
			num = cusHandoverLstDao.deleteByPk(cusHandoverLst);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inCusHandoverLstVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(CusHandoverLstVO inCusHandoverLstVo) {
		logger.debug("当前修改数据为:"+ inCusHandoverLstVo.toString());
		int num = 0;
		try {
			CusHandoverLst cusHandoverLst = new CusHandoverLst();
			beanCopy(inCusHandoverLstVo, cusHandoverLst);
			num = cusHandoverLstDao.updateByPk(cusHandoverLst);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inCusHandoverLstVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public CusHandoverLstVO queryByPk(CusHandoverLstVO inCusHandoverLstVo) {
		
		logger.debug("当前查询参数信息为:"+ inCusHandoverLstVo);
		try {
			CusHandoverLst queryCusHandoverLst = new CusHandoverLst();
			beanCopy(inCusHandoverLstVo, queryCusHandoverLst);
			CusHandoverLst queryRslCusHandoverLst = cusHandoverLstDao.queryByPk(queryCusHandoverLst);
			if (Objects.nonNull(queryRslCusHandoverLst)) {
				CusHandoverLstVO outCusHandoverLstVo = beanCopy(queryRslCusHandoverLst, new CusHandoverLstVO());
				logger.debug("当前查询结果为:"+ outCusHandoverLstVo.toString());
				return outCusHandoverLstVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<CusHandoverLstVO> queryAllOwner(CusHandoverLstVO cusHandoverLstVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<CusHandoverLstVO> list = null;
		try {
			List<CusHandoverLst> cusHandoverLsts = cusHandoverLstDao.queryAllOwnerByPage(cusHandoverLstVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ cusHandoverLsts.size());
			pageSet(cusHandoverLsts, cusHandoverLstVo);
			list = (List<CusHandoverLstVO>) beansCopy(cusHandoverLsts, CusHandoverLstVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<CusHandoverLstVO> queryAllCurrOrg(CusHandoverLstVO cusHandoverLstVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<CusHandoverLst> cusHandoverLsts = cusHandoverLstDao.queryAllCurrOrgByPage(cusHandoverLstVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+cusHandoverLsts.size());
		List<CusHandoverLstVO> list = null;
		try {
			pageSet(cusHandoverLsts, cusHandoverLstVo);
			list = (List<CusHandoverLstVO>) beansCopy(cusHandoverLsts, CusHandoverLstVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<CusHandoverLstVO> queryAllCurrDownOrg(CusHandoverLstVO cusHandoverLstVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<CusHandoverLst> cusHandoverLsts = cusHandoverLstDao.queryAllCurrDownOrgByPage(cusHandoverLstVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ cusHandoverLsts.size());
		List<CusHandoverLstVO> list = null;
		try {
			pageSet(cusHandoverLsts, cusHandoverLstVo);
			list = (List<CusHandoverLstVO>) beansCopy(cusHandoverLsts, CusHandoverLstVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@SuppressWarnings("unchecked")
	public List<CusHandoverLstVO> queryAllBySerno(CusHandoverLstVO cusHandoverLstVo) {
		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:" +cusHandoverLstVo);
		CusHandoverLst cusHandoverLst = new CusHandoverLst();
		cusHandoverLst.setSerno(cusHandoverLstVo.getSerno());
		cusHandoverLst = beanCopy(cusHandoverLstVo,cusHandoverLst);
		List<CusHandoverLst> cusHandoverLsts = cusHandoverLstDao.queryBySerno(cusHandoverLst);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ cusHandoverLsts.size());
		List<CusHandoverLstVO> list = null;
		try {
			pageSet(cusHandoverLsts, cusHandoverLstVo);
			list = (List<CusHandoverLstVO>) beansCopy(cusHandoverLsts, CusHandoverLstVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CusHandoverLstVO> queryDetailsBySerno(CusHandoverLstVO inCusHandoverLstVo) {
		logger.debug("当前根据客户移交申请流水号查询客户移交明细的参数信息为:" +inCusHandoverLstVo);
		List<CusHandoverLst> cusHandoverLsts = cusHandoverLstDao.queryDetailsBySernoByPage(inCusHandoverLstVo);
		logger.debug("当前根据客户移交申请流水号查询客户移交明细的结果集数量为:"+ cusHandoverLsts.size());
		List<CusHandoverLstVO> list = null;
		try {
			pageSet(cusHandoverLsts, inCusHandoverLstVo);
			list = (List<CusHandoverLstVO>) beansCopy(cusHandoverLsts, CusHandoverLstVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

}
